<template>
  <div class="app-container">
    <el-row :gutter="20" type="flex">
      <el-col style="width: 300px;">
        <pointList v-on:handlePointClick="handlePointClick"></pointList>
      </el-col>
      <el-col>
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
          <el-form-item label="时间">
            <el-date-picker
              v-model="dateRange"
              :clearable="false"
              :editable="false"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="remoteControlRecordList" >
<!--          <el-table-column type="selection" width="55" align="center" />-->
          <el-table-column label="操作时间" align="center" prop="recTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.recTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作员" align="center" prop="operName" width="120"/>
          <el-table-column label="操作类型" align="center" prop="operType" width="120" :formatter="operTypeFormat" />
          <el-table-column label="报文类型" align="center" prop="txtType" width="100" :formatter="txtTypeFormat"/>
          <el-table-column label="报文" align="left" prop="msgTxt" />
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

      </el-col>
    </el-row>

  </div>
</template>

<script>
  import pointList from "@/views/components/pointTreeList";
  import { listRemoteControlRecord } from "@/api/basic/remoteControlRecord";

  export default {
  name: "DutyHisBidtest",
  components: { pointList },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 远程控制记录表格数据
      remoteControlRecordList: [],
      txtTypeOptions:[{dictLabel:'下载',dictValue:'down'},{dictLabel:'上载',dictValue:'up'}],
      operTypeOptions:[],
      // 日期范围
      dateRange: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pointId: null,
        operType: null,
      },
    };
  },
    mounted() {
      let nowDate = new Date();
      let befDate = new Date(nowDate.getTime() + 1 * 24 * 3600 * 1000);
      let byear = befDate.getFullYear();
      let bmonth = befDate.getMonth() + 1;
      let bday = befDate.getDate();
      let endTime = `${byear}-${bmonth}-${bday}`;
      // 向前推迟一周的时间点
      befDate = new Date(nowDate.getTime() - 7 * 24 * 3600 * 1000);
      byear = befDate.getFullYear();
      bmonth = befDate.getMonth() + 1;
      bday = befDate.getDate();
      let startTime = `${byear}-${bmonth}-${bday}`;
      this.dateRange = [startTime,endTime];
    },
  created() {
    this.getDicts("basic_oper_type").then(response => {
      this.operTypeOptions = response.data;
    });
  },
  methods: {
    /** 查询远程控制记录列表 */
    getList() {
      this.loading = true;
      listRemoteControlRecord(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.remoteControlRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 操作类型字典翻译
    operTypeFormat(row, column) {
      return this.selectDictLabel(this.operTypeOptions, row.operType);
    },
    txtTypeFormat(row, column) {
      return this.selectDictLabel(this.txtTypeOptions, row.txtType);
    },
    handlePointClick(obj){
      this.queryParams.pointId=obj.pointId;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    }
  }
};
</script>
